package com.kaba.security.handler;

import com.alibaba.fastjson.JSON;
import com.kaba.bean.ResponseResult;
import com.kaba.bean.ResultTool;
import com.kaba.bean.json.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author lvmengjie
 * @Date 2021/3/24
 * @Description 账号登出处理逻辑
 */
@Component
public class CustomizeLogoutSuccessHandler implements LogoutSuccessHandler {

    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {

        redisTemplate.delete("kabam");
        String data="logoutsuccess";
        System.out.println("退出");
        ResponseResult result = ResponseResult.success(data);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(JSON.toJSONString(result));

    }
}
